<?php

namespace Library\Traits;

trait HasInstance
{
    /**
     * @param ...$args
     * @return self
     */
    public static function make(...$args): static
    {
        if (!(self::$instance instanceof self)) {
            // 使用临时变量实现双重检查锁定
            static $instanced = false;
            if (!$instanced) {
                $instanced = true;
                self::$instance = new self(...$args);
            }
        }
        return self::$instance;
    }
}